package com.junwell.config;

import com.junwell.quartz.RedisJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Junwell
 * @date 2023/3/7 21:26
 */
@Configuration
public class QuartzConfig {

    @Bean
    public JobDetail helloJobDetail() {
        return JobBuilder.newJob(RedisJob.class)
                .withIdentity("job1", "group")
                .usingJobData("message","打印日志")
                .storeDurably(true)
                .build();
    }

    @Bean
    public Trigger printTimeJobTrigger() {
        // 每天八点
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("0 0 2 * * ?");
        return TriggerBuilder.newTrigger()
                .forJob(helloJobDetail())
                .withIdentity("trigger1", "group")
                .withSchedule(cronScheduleBuilder)
                .build();
    }
}
